]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell: Check we are in a systemd environment before starting systemd units
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 6 May 2020 08:57:54 +0000 (10:57 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 7 May 2020 10:16:11 +0000 (12:16 +0200)
Avoid starting/stopping the gsd-xsettings systemd unit if the shell itself
was not started via systemd. In the lack of a user session manager, we
have no means to neatly start/stop services, so should rely on the good
ol' gnome-session to do this for us.

This changes the return value meaning slightly, TRUE means "service did
start", FALSE otherwise. The error is only raised if we ought to start,
but it produced an error somehow.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1238
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2755

src/shell-util.c

index bb2329536bfbc5de02b77132b84b5d8b887d4fa5..dd6d312f497ffcabbab0701650f292eaf38ebd94 100644 (file)
@@ -31,6 +31,7 @@
 
 #ifdef HAVE_SYSTEMD
 #include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
 #else
 /* So we don't need to add ifdef's everywhere */
 #define sd_notify(u, m)            do {} while (0)
@@ -673,7 +674,27 @@ shell_util_systemd_call (const char  *command,
                          const char  *mode,
                          GError     **error)
 {
+#ifdef HAVE_SYSTEMD
   g_autoptr (GDBusConnection) connection = NULL;
+  g_autofree char *self_unit = NULL;
+  int res;
+
+  res = sd_pid_get_user_unit (getpid (), &self_unit);
+
+  if (res == -ENODATA)
+    {
+      g_debug ("Not systemd-managed, not doing '%s' on '%s'", mode, unit);
+      return FALSE;
+    }
+  else if (res < 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   g_io_error_from_errno (-res),
+                   "Error trying to start systemd unit '%s': %s",
+                   unit, g_strerror (-res));
+      return FALSE;
+    }
 
   connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
 
@@ -692,7 +713,9 @@ shell_util_systemd_call (const char  *command,
                           -1, NULL,
                           on_systemd_call_cb,
                           (gpointer) command);
-  return TRUE;
+#endif /* HAVE_SYSTEMD */
+
+  return FALSE;
 }
 
 gboolean